package com.coocaa.ops.admin.base.event.listener;

import com.coocaa.ops.admin.base.event.AlterTransactionalEvent;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @author bjh
 * @description
 * @date 2021/1/26 10:29
 */

@Component
public class AlterTransactionListener {
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void onHandler(AlterTransactionalEvent event) {
        AlterTransactionalEvent.Apply apply = event.getSource();
        if (apply != null) {
            // 因为我们传入的是一个lambda表达式，所以可以像使用匿名函数一样去调用这个执行过程
            apply.apply();
        }
    }

}
